package cn.cloudreal.cbms.material.action;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.net.URLDecoder;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;

import cn.cloudreal.cbms.common.util.Constants;
import cn.cloudreal.cbms.common.util.DatadicContext;
import cn.cloudreal.cbms.common.util.PageBean;
import cn.cloudreal.cbms.log.service.OptLogService;
import cn.cloudreal.cbms.material.service.MaterialService;
import cn.cloudreal.cbms.mediaPrice.action.MediaPriceAction;
import cn.cloudreal.cbms.system.service.OrganizaService;
import cn.cloudreal.cbms.vo.Dictionary;
import cn.cloudreal.cbms.vo.Log;
import cn.cloudreal.cbms.vo.Material;
import cn.cloudreal.cbms.vo.Organiza;
import cn.cloudreal.cbms.vo.UserInfo;

import com.opensymphony.xwork2.ActionSupport;

public class MaterialAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private MaterialService materialService = null;
	private OrganizaService organizaService = null;
	private OptLogService optLogService = null;
	private List<Material> list = null;
	private List<Log> logList = null;

	// 列表显示
	private Material materiales = null;

	// 新增物料信息
	private Material material = null;

	// 编辑物料信息
	private Material materialEdit = null;

	// 保存编辑后的物料信息
	private Material saveMaterialEdit = null;

	// 详细物料信息
	private Material materialDetail = null;
	/**
	 * 返回树形菜单字符串
	 */
	private String flag = null;

	// 上传文件
	private File inputfile;
	private String inputfileFileName;
	private String inputfileContentType;

	/** 下载 */
	private String fileName;
	private InputStream downloadStream;

	private String materialContent; // 物料文件路径

	/**
	 * 搜索功能定义的字段
	 */
	private String firstStratTime = null;

	private String firstEndTime = null;
	private int materialOfSelect;// 下拉框——搜索关键字
	private String keyOfWord;
	private String city;// 下拉框——归属地市
	private String type;// 下拉框——物料类型
	private String business;// 下拉框——业务类型
	private int matId = 0;// 物料库的id
	private int id = 0;
	private String types = null;
	private String code = null;

	private List<Dictionary> dataListWLLX = null;// 物料类型
	private List<Dictionary> dataListWLYWLX = null;// 业务类型
	private List<Dictionary> dataListCITY = null;// 所属城市
	private List<Dictionary> dataListWLJB = null;// 物料级别
	private List<Organiza> organizaLists = null; // 组织架构

	private String tempMaterial; // 组合物料编号

	private String tempMaterial1;// 编辑页面组合物料编号
	private String tempMaterial2;// 编辑页面获取的物料编号

	/** 当前页 */
	private int currentPage;

	/** 分页对象 */
	private PageBean page;

	/** 日志工具类实例 */
	private static final Logger log = Logger.getLogger(MediaPriceAction.class);

	/**
	 * 显示物料的列表
	 */
	public String list() {
		// 打印进入方法体日志
		if (log.isInfoEnabled()) {
			log.info("Enter MaterialAction list() method, return String");
		}
		try {
			if (materiales == null) {
				materiales = new Material();
			}
			initializeData();
			materiales.setFirstUpTime(firstStratTime);
			materiales.setDocumentDate(firstEndTime);

			// 归属地市的权限设置
			UserInfo userInfo = (UserInfo) ServletActionContext.getRequest()
					.getSession().getAttribute(Constants.SESSIONPRKEY);
			// 非空
			if (null != userInfo && city == null) {
				city = "DG";
				if (userInfo.getUserRole() != null) {
					// 非空重置
					if (userInfo.getUsercity() != null) {
						if (!"".equals(userInfo.getUsercity())) {
							city = userInfo.getUsercity();
						}
					}
					// 操作范围
					String roleRange = userInfo.getUserRole().getRoleRange();
					if (roleRange != null) {
						// 地市级
						if ("2".endsWith(roleRange) || "3".endsWith(roleRange)) {
							dataListCITY.clear();
							Dictionary dictionary = (Dictionary) DatadicContext
									.getInstance().getDatadicObject(city,
											"CITY");
							dataListCITY.add(dictionary);

						}
					}
				}
			}

			// 下拉框物料类型
			if (null != type && !"".equals(type)) {
				if (!type.equals(0)) {
					materiales.setMaterialType(type);
				}
			}
			// 下拉框业务类型
			if (null != business && !"".equals(business)) {
				if (!business.equals(0)) {
					materiales.setServiceType(business);
				}
			}

			/**
			 * 下拉框——关键字的选择
			 */
			if (materialOfSelect == 1) {
				String key = "请输入关键字";
				if (keyOfWord.equals(key)) {
					keyOfWord = "";
				} else {
					keyOfWord = keyOfWord.replaceAll("\\s", "").toString();// 屏蔽空格
				}
				materiales.setMaterialID(keyOfWord);
			}

			// 实例化 page分页对象
			System.out.println("currentPage==" + currentPage);
			page = new PageBean(currentPage == 0 ? 1 : currentPage, 10);
			materiales.setOwnCity(city);
			list = materialService.getMaterialList(page, materiales);
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}
		// 打印退出方法体日志
		if (log.isInfoEnabled()) {
			log.info("Exit MaterialAction list() method, return String");
		}
		return SUCCESS;
	}

	/**
	 * 下载文件
	 * 
	 * @return
	 * @throws Exception
	 */
	public String down() throws Exception {
		try {
			HttpServletRequest request = ServletActionContext.getRequest();
			String path = request.getSession().getServletContext().getRealPath(
					"/");

			fileName = URLDecoder.decode(fileName, "UTF-8");
			String realpath = path + getText("material.file.path") + fileName;

			System.out.println(realpath);
			File file = null;
			file = new File(realpath);

			// 判断文件路径是否存在文件，如果不存在直接返回异常
			if (!file.exists()) {
				return null;
			}
			// 下载流
			// fileName = fileName + UUID.randomUUID();
			// 中文文件名转码
			fileName = new String(fileName.getBytes(), "ISO8859-1");
			downloadStream = new FileInputStream(realpath);

		} catch (Exception e) {
			return ERROR;
		}
		return "export_download";
	}

	/**
	 * 跳转到新增页面
	 */
	public String turnToAdd() {
		try {
			if (material == null) {
				material = new Material();
			}
			// 初始化下拉框数据
			initializeData();

			// 归属地市的权限设置
			UserInfo userInfo = (UserInfo) ServletActionContext.getRequest()
					.getSession().getAttribute(Constants.SESSIONPRKEY);
			String cityCode = userInfo.getUsercity();
			// 查询组织架构信息 获取当前节点集合
			organizaLists = new ArrayList<Organiza>();
			organizaLists = organizaService.getOrganizaByCity(cityCode);
			// 获取生成组织架构字符串
			flag = Constants.getOrganizaTree(organizaLists);
			if (null != userInfo) {
				city = "DG";
				if (userInfo.getUserRole() != null) {
					// 非空重置
					if (userInfo.getUsercity() != null) {
						if (!"".equals(userInfo.getUsercity())) {
							city = userInfo.getUsercity();
						}
					}
					// 操作范围
					String roleRange = userInfo.getUserRole().getRoleRange();
					if (roleRange != null) {

						// 地市级
						if ("2".endsWith(roleRange) || "3".endsWith(roleRange)
								|| "1".endsWith(roleRange)) {
							dataListCITY.clear();
							Dictionary dictionary = (Dictionary) DatadicContext
									.getInstance().getDatadicObject(city,
											"CITY");
							dataListCITY.add(dictionary);

						}
					}
				}
			}
			material.setOwnCity(city);

		} catch (Exception e) {
			e.printStackTrace();
			log.info("Exit MaterialAction turnToAdd() method, return String");
			return ERROR;
		}
		return SUCCESS;
	}

	/**
	 * 保存新增信息并跳转到列表页面
	 */
	public String saveMaterial() {
		// 初始化下拉框数据
		initializeData();
		HttpServletRequest request = ServletActionContext.getRequest();
		String path = request.getSession().getServletContext().getRealPath("/");
		try {
			// 根据页面数据生成物料编号
			material.setMaterialID(getTheMaterialId(material));
			// 若有文件，则上传文件
			if (null != inputfile && inputfile.exists()) {
				System.out.println(inputfileFileName);
				Constants.upload(inputfile, inputfileFileName, path
						+ getText("material.file.path"));
			}
			// 获取上传文件名
			String fileName = inputfileFileName == null ? ""
					: inputfileFileName;
			// 若有文件上传，则将文件重命名，命名规则：物料编号+文件后缀名，保证命名不重复
			if (fileName != "" && fileName != null) {
				fileName = fileName.substring(fileName.lastIndexOf("."));
				fileName = material.getMaterialID() + fileName;
				File beforeFile = new File(path + getText("material.file.path")
						+ inputfileFileName);
				File newFile = new File(path + getText("material.file.path")
						+ fileName);
				beforeFile.renameTo(newFile);
			}
			// 获取文件名
			material.setMaterialContent(fileName);
			// 将数据存入数据库，并返回自增id
			Integer addId = materialService.addMaterial(material);
			// 打印日志
			UserInfo userSession = (UserInfo) ServletActionContext.getRequest()
					.getSession().getAttribute("logUser");
			String user = null;
			String cityCode = null;
			String cityName = null;
			String organizaOragName = null;

			user = userSession.getUserName() == null ? "" : userSession
					.getUserName();
			cityCode = userSession.getUsercity() == null ? "" : userSession
					.getUsercity();
			cityName = userSession.getCityName() == null ? "" : userSession
					.getCityName();
			organizaOragName = userSession.getOrganiza().getOrgName() == null ? ""
					: userSession.getOrganiza().getOrgName();

			Timestamp d = new Timestamp(System.currentTimeMillis());
			String content = d + cityName + organizaOragName + user + "创建物料表";
			String datatime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS")
					.format(new Date());
			/** 获取变更记录的数据 */
			Log logRecord = new Log("T_CB_MATERIAL", content, addId + "",
					datatime, user, cityCode, organizaOragName, "科室");
			optLogService.addLog(logRecord);
			this.alertMessage("物料信息添加成功！", "materiallist.action");

		} catch (Exception e) {
			e.printStackTrace();
			// 打印异常方法体日志
			log.error("Exception ContractListAction saveContract() method", e);
			return ERROR;
		}
		return SUCCESS;
	}

	/**
	 * 获取物料编号
	 */
	private String getTheMaterialId(Material mat) {
		String name = mat.getMaterialName();
		String city = mat.getOwnCity();
		String service = mat.getServiceType();
		String type = mat.getMaterialType();
		int order = mat.getOrderCol();
		String firstTime = mat.getFirstUpTime();
		String sub1 = firstTime.substring(2, 4);
		String sub2 = firstTime.substring(5, 7);
		String sub = sub1 + sub2;
		String orderOfSring = String.valueOf(order);
		if (orderOfSring.length() < 2) {
			orderOfSring = "0" + orderOfSring;
		}
		String materialID = city + "-" + service + "-" + type + "-" + sub + "-"
				+ orderOfSring + "-" + name;
		System.out.println(materialID);
		return materialID;

	}

	/**
	 * 跳转到编辑页面
	 */
	public String turnToUpdate() {
		try {
			initializeData();
			// 归属地市的权限设置
			UserInfo userInfo = (UserInfo) ServletActionContext.getRequest()
					.getSession().getAttribute(Constants.SESSIONPRKEY);
			String cityCode = userInfo.getUsercity();
			organizaLists = new ArrayList<Organiza>();
			organizaLists = organizaService.getOrganizaByCity(cityCode);
			// 获取生成组织架构字符串
			flag = Constants.getOrganizaTree(organizaLists);
			materialEdit = materialService.detailMaterial(matId);
			if (materialEdit != null) {

				String departments = materialEdit.getOwnDepartment();
				if (!"".equals(departments) && departments != null) {
					materialEdit
							.setOwnDepartment(lookForDepartment(departments));
				}
				// 非空
				if (null != userInfo) {
					city = "DG";
					//
					if (userInfo.getUserRole() != null) {
						// 非空重置
						if (userInfo.getUsercity() != null) {
							if (!"".equals(userInfo.getUsercity())) {
								city = userInfo.getUsercity();
							}
						}
						// 操作范围
						String roleRange = userInfo.getUserRole()
								.getRoleRange();
						if (roleRange != null) {

							// 地市级
							if ("2".endsWith(roleRange)
									|| "3".endsWith(roleRange)
									|| "1".endsWith(roleRange)) {
								dataListCITY.clear();
								Dictionary dictionary = (Dictionary) DatadicContext
										.getInstance().getDatadicObject(city,
												"CITY");
								dataListCITY.add(dictionary);

							}
						}
					}
				}
				materialEdit.setOwnCity(city);
			}

		} catch (Exception e) {
			return ERROR;
		}
		return SUCCESS;

	}

	/**
	 * 通过 ownDepartment的orgCode查找orgName
	 * 
	 * @param departments
	 * @return
	 */
	private String lookForDepartment(String orgCode) {
		String orgName = null;
		List<Organiza> organizaL = new ArrayList<Organiza>();
		Organiza organiza = new Organiza();
		organiza.setOrgCode(orgCode);
		// 查询组织架构信息 获取当前节点集合
		organizaL = organizaService.getOrganizas(organiza);
		orgName = organizaL.get(0).getOrgName();
		return orgName;
	}

	/**
	 * 删除物料文件
	 */
	public String deleteContent() {

		HttpServletRequest request = ServletActionContext.getRequest();
		String path = request.getSession().getServletContext().getRealPath("/");
		// response 对象
		HttpServletResponse response = ServletActionContext.getResponse();
		PrintWriter out = null;
		try {
			materialContent = URLDecoder.decode(materialContent, "UTF-8");
			ServletActionContext.getRequest().setCharacterEncoding(
					Constants.STR_UTF);
			response.setContentType(Constants.STR_CHARSET);
			out = response.getWriter();
			if (materialService.isExitContent(materialContent)) {

				initializeData();
				// 获取PrintWriter对象
				// 删除文件
				String reallypath = path + getText("material.file.path")
						+ materialContent;
				System.out.println("文件路径为：" + reallypath);
				File f = new File(reallypath);
				if (f.exists() && f.isFile()) {
					f.delete();
					// 删除文件在数据库的对应字段
					materialService.deleteContent(materialContent);
				}
				out.print("success");
			} else {
				out.print("error");
			}
		} catch (Exception e) {
			e.printStackTrace();
			out.print("error");
		}
		return null;
	}

	/**
	 * 编辑页面的保存 File inputfile; //上传的文件 String inputfileFileName; //上传文件的名称
	 * String inputfileContentType;//上传文件的类型
	 */
	public String saveEdit() {
		HttpServletRequest request = ServletActionContext.getRequest();
		String path = request.getSession().getServletContext().getRealPath("/");
		// 初始化下拉框数据
		initializeData();
		// 编辑前该条数据的物料编号
		String id1 = saveMaterialEdit.getMaterialID();
		// 编辑后该条数据的物料编号
		String id2 = getTheMaterialId(saveMaterialEdit);
		try {

			if (materialService.detailMaterial(saveMaterialEdit.getMatId()) != null) {

				// 有文件上传
				if (inputfile != null) {
					// 之前已存在物料文件，先删除该物料文件
					if (saveMaterialEdit.getMaterialContent() != ""
							|| saveMaterialEdit.getMaterialContent() != null) {
						String beforePath = path
								+ getText("material.file.path")
								+ saveMaterialEdit.getMaterialContent();
						File bFile = new File(beforePath);
						if (bFile.exists() && bFile.isFile()) {
							bFile.delete();
						}
					}
					Constants.upload(inputfile, inputfileFileName, path
							+ getText("material.file.path"));
					System.out.println(inputfileFileName);
					// String fileName =
					// inputfileFileName==null?saveMaterialEdit.getMaterialContent():inputfileFileName;
					String fileName = inputfileFileName;
					// 为上传的文件重命名，命名规则：物料编号+文件后缀名
					if (fileName != "") {
						fileName = fileName
								.substring(fileName.lastIndexOf("."));
						fileName = id2 + fileName;
						File beforeFile = new File(path
								+ getText("material.file.path")
								+ inputfileFileName);
						File newFile = new File(path
								+ getText("material.file.path") + fileName);
						beforeFile.renameTo(newFile);
					}
					saveMaterialEdit.setMaterialContent(fileName);// 获取文件名
				} else {
					// 无物料文件上传，之前已上传了物料文件
					if (null != saveMaterialEdit.getMaterialContent()
							&& !""
									.equals(saveMaterialEdit
											.getMaterialContent())) {
						// 编辑后生成的物料编号与之前的物料编号不同，则为文件重命名，对应数据库的字段也要更新
						if (id1 != id2) {
							String bName = saveMaterialEdit
									.getMaterialContent();
							bName = bName.substring(bName.lastIndexOf("."));
							bName = id2 + bName;
							File aaFile = new File(path
									+ getText("material.file.path") + bName);
							File bbFile = new File(path
									+ getText("material.file.path")
									+ saveMaterialEdit.getMaterialContent());
							bbFile.renameTo(aaFile);
							// 文件对应的数据库字段重设置
							saveMaterialEdit.setMaterialContent(bName);
						}
					}
				}
				// 重设物料编号
				saveMaterialEdit.setMaterialID(id2);
				// 更新数据库该条记录的信息
				materialService.updateMaterial(saveMaterialEdit);
				// 打印日志
				UserInfo userSession = (UserInfo) ServletActionContext
						.getRequest().getSession().getAttribute("logUser");
				String user = null;
				String cityCode = null;
				String cityName = null;
				String organizaOragName = null;

				user = userSession.getUserName() == null ? "" : userSession
						.getUserName();
				cityCode = userSession.getUsercity() == null ? "" : userSession
						.getUsercity();
				cityName = userSession.getCityName() == null ? "" : userSession
						.getCityName();
				organizaOragName = userSession.getOrganiza().getOrgName() == null ? ""
						: userSession.getOrganiza().getOrgName();
				Timestamp d = new Timestamp(System.currentTimeMillis());
				String content = d + cityName + organizaOragName + user
						+ "修改物料表";
				String datatime = new SimpleDateFormat(
						"yyyy-MM-dd HH:mm:ss.SSS").format(new Date());
				/** 获取变更记录的数据 */
				Log logRecord = new Log("T_CB_MATERIAL", content,
						saveMaterialEdit.getMatId() + "", datatime, user,
						cityCode, organizaOragName, "科室");
				optLogService.addLog(logRecord);
				this.alertMessage("物料信息修改成功！", "materiallist.action");
			} else {
				return ERROR;
			}

		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}
		return SUCCESS;
	}

	/**
	 * 跳转到详情页面
	 */
	public String turnToDetail() {
		try {
			initializeData();
			System.out.println("matId" + matId);
			materialDetail = materialService.detailMaterial(matId);
			if (materialDetail != null) {

				String depart = materialDetail.getOwnDepartment();
				if (!"".equals(depart) && depart != null) {
					materialDetail.setOwnDepartment(lookForDepartment(depart));
				}
				Log sample = new Log();
				sample.setRelationId(materialDetail.getMatId() + "");
				sample.setLogType("T_CB_MATERIAL");
				logList = new ArrayList<Log>();
				logList = optLogService.getLogsBySample(sample);
			}

		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}
		return SUCCESS;

	}

	/**
	 * 删除物料信息
	 */
	public String delete() {
		initializeData();
		HttpServletRequest request = ServletActionContext.getRequest();
		String path = request.getSession().getServletContext().getRealPath("/");
		// response 对象
		HttpServletResponse response = ServletActionContext.getResponse();
		PrintWriter out = null;
		try {
			ServletActionContext.getRequest().setCharacterEncoding(
					Constants.STR_UTF);
			response.setContentType(Constants.STR_CHARSET);
			out = response.getWriter();
			// 获取PrintWriter对象
			Material m = new Material();
			if (materialService.detailMaterial(matId) != null) {

				if (materialService.isExitIDInPM(matId)) {

					m = materialService.detailMaterial(matId);
					String contents = m.getMaterialContent();
					// 调用删除函数
					materialService.deleteMaterial(matId);
					// 删除上传的物料文件
					String reallypath = path + getText("material.file.path")
							+ contents;
					System.out.println("文件路径为：" + reallypath);
					File f = new File(reallypath);
					if (f.exists() && f.isFile()) {
						f.delete();
					}
					// 打印日志
					UserInfo userSession = (UserInfo) ServletActionContext
							.getRequest().getSession().getAttribute("logUser");
					String user = null;
					String cityCode = null;
					String cityName = null;
					String organizaOragName = null;

					user = userSession.getUserName() == null ? "" : userSession
							.getUserName();
					cityCode = userSession.getUsercity() == null ? ""
							: userSession.getUsercity();
					cityName = userSession.getCityName() == null ? ""
							: userSession.getCityName();
					organizaOragName = userSession.getOrganiza().getOrgName() == null ? ""
							: userSession.getOrganiza().getOrgName();

					Timestamp d = new Timestamp(System.currentTimeMillis());
					String content = d + cityName + organizaOragName + user
							+ "删除物料表";
					String datatime = new SimpleDateFormat(
							"yyyy-MM-dd HH:mm:ss.SSS").format(new Date());
					/** 获取变更记录的数据 */
					Log logRecord = new Log("T_CB_MATERIAL", content, matId
							+ "", datatime, user, cityCode, organizaOragName,
							"科室");
					optLogService.addLog(logRecord);
					out.print("success");
				} else {
					out.print("beUsed");
				}
			} else {
				out.print("isDeleted");
			}
		} catch (Exception e) {
			e.printStackTrace();
			out.print("error");
		}
		return null;
	}

	// 新增中判断是否存在相同物料编号
	public String isExistMaterialID() {
		// response 对象
		HttpServletResponse response = ServletActionContext.getResponse();
		PrintWriter out = null;
		try {
			tempMaterial = URLDecoder.decode(tempMaterial, "UTF-8");
			if (!materialService.isTheUniqueId(tempMaterial)) {
				// 获取PrintWriter对象
				ServletActionContext.getRequest().setCharacterEncoding(
						Constants.STR_UTF);
				response.setContentType(Constants.STR_CHARSET);
				out = response.getWriter();
				out.print("success");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	// 编辑中判断是否存在相同物料编号
	public String isExistEditMaterialID() {

		// response 对象
		HttpServletResponse response = ServletActionContext.getResponse();
		PrintWriter out = null;
		try {
			tempMaterial1 = URLDecoder.decode(tempMaterial1, "UTF-8");
			tempMaterial2 = URLDecoder.decode(tempMaterial2, "UTF-8");
			// 获取PrintWriter对象
			ServletActionContext.getRequest().setCharacterEncoding(
					Constants.STR_UTF);
			response.setContentType(Constants.STR_CHARSET);
			out = response.getWriter();
			if (tempMaterial1.equals(tempMaterial2)) {
				out.print("equals");
			} else if (!materialService.isTheUniqueId(tempMaterial1)) {
				out.print("success");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * 初始化下拉框的数据
	 */
	private void initializeData() {
		/**
		 * 下拉框——物料类型的选择
		 */
		dataListWLLX = DatadicContext.getInstance()
				.getDicDataListByCode("WLLX");

		/**
		 * 下拉框——所属城市的选择
		 */
		dataListCITY = DatadicContext.getInstance()
				.getDicDataListByCode("CITY");

		/**
		 * 下拉框——业务类型的选择
		 */
		dataListWLYWLX = DatadicContext.getInstance().getDicDataListByCode(
				"WLYWLX");

		/**
		 * 物料级别
		 */
		dataListWLJB = DatadicContext.getInstance()
				.getDicDataListByCode("WLJB");

	}

	/**
	 * 弹出提示信息
	 */
	private void alertMessage(String message, String url) {
		try {
			HttpServletResponse response = ServletActionContext.getResponse();
			response.setCharacterEncoding("UTF-8");
			response.setContentType("text/html; charset=utf-8");
			PrintWriter out = response.getWriter();
			out = response.getWriter();
			out.println(" <script type='text/javascript' >");
			out.println("alert('" + message + "');");
			out.println("location='" + url + "'");
			out.println(" </script>");
			out.flush();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * get ,set 方法
	 * 
	 * @return
	 */

	public MaterialService getMaterialService() {
		return materialService;
	}

	public void setMaterialService(MaterialService materialService) {
		this.materialService = materialService;
	}

	public List<Material> getList() {
		return list;
	}

	public void setList(List<Material> list) {
		this.list = list;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public PageBean getPage() {
		return page;
	}

	public void setPage(PageBean page) {
		this.page = page;
	}

	public static Logger getLog() {
		return log;
	}

	public String getFirstStratTime() {
		return firstStratTime;
	}

	public void setFirstStratTime(String firstStratTime) {
		this.firstStratTime = firstStratTime;
	}

	public String getFirstEndTime() {
		return firstEndTime;
	}

	public void setFirstEndTime(String firstEndTime) {
		this.firstEndTime = firstEndTime;
	}

	public int get() {
		return materialOfSelect;
	}

	public void setMaterialOfSelect(int materialOfSelect) {
		this.materialOfSelect = materialOfSelect;
	}

	public String getKeyOfWord() {
		return keyOfWord;
	}

	public void setKeyOfWord(String keyOfWord) {
		this.keyOfWord = keyOfWord;
	}

	public List<Dictionary> getDataListWLLX() {
		return dataListWLLX;
	}

	public void setDataListWLLX(List<Dictionary> dataListWLLX) {
		this.dataListWLLX = dataListWLLX;
	}

	public Material getMaterial() {
		return material;
	}

	public void setMaterial(Material material) {
		this.material = material;
	}

	public List<Dictionary> getDataListCITY() {
		return dataListCITY;
	}

	public void setDataListCITY(List<Dictionary> dataListCITY) {
		this.dataListCITY = dataListCITY;
	}

	public List<Dictionary> getDataListWLYWLX() {
		return dataListWLYWLX;
	}

	public void setDataListWLYWLX(List<Dictionary> dataListWLYWLX) {
		this.dataListWLYWLX = dataListWLYWLX;
	}

	public Material getMateriales() {
		return materiales;
	}

	public void setMateriales(Material materiales) {
		this.materiales = materiales;
	}

	public int getMatId() {
		return matId;
	}

	public void setMatId(int matId) {
		this.matId = matId;
	}

	public File getInputfile() {
		return inputfile;
	}

	public void setInputfile(File inputfile) {
		this.inputfile = inputfile;
	}

	public String getInputfileFileName() {
		return inputfileFileName;
	}

	public void setInputfileFileName(String inputfileFileName) {
		this.inputfileFileName = inputfileFileName;
	}

	public String getInputfileContentType() {
		return inputfileContentType;
	}

	public void setInputfileContentType(String inputfileContentType) {
		this.inputfileContentType = inputfileContentType;
	}

	public Material getMaterialEdit() {
		return materialEdit;
	}

	public void setMaterialEdit(Material materialEdit) {
		this.materialEdit = materialEdit;
	}

	public Material getMaterialDetail() {
		return materialDetail;
	}

	public void setMaterialDetail(Material materialDetail) {
		this.materialDetail = materialDetail;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public Material getSaveMaterialEdit() {
		return saveMaterialEdit;
	}

	public void setSaveMaterialEdit(Material saveMaterialEdit) {
		this.saveMaterialEdit = saveMaterialEdit;
	}

	public int getMaterialOfSelect() {
		return materialOfSelect;
	}

	public String getMaterialContent() {
		return materialContent;
	}

	public void setMaterialContent(String materialContent) {
		this.materialContent = materialContent;
	}

	public String getBusiness() {
		return business;
	}

	public void setBusiness(String business) {
		this.business = business;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public InputStream getDownloadStream() {
		return downloadStream;
	}

	public void setDownloadStream(InputStream downloadStream) {
		this.downloadStream = downloadStream;
	}

	public String getTempMaterial() {
		return tempMaterial;
	}

	public void setTempMaterial(String tempMaterial) {
		this.tempMaterial = tempMaterial;
	}

	public String getTempMaterial1() {
		return tempMaterial1;
	}

	public void setTempMaterial1(String tempMaterial1) {
		this.tempMaterial1 = tempMaterial1;
	}

	public String getTempMaterial2() {
		return tempMaterial2;
	}

	public void setTempMaterial2(String tempMaterial2) {
		this.tempMaterial2 = tempMaterial2;
	}

	public OrganizaService getOrganizaService() {
		return organizaService;
	}

	public void setOrganizaService(OrganizaService organizaService) {
		this.organizaService = organizaService;
	}

	public String getFlag() {
		return flag;
	}

	public void setFlag(String flag) {
		this.flag = flag;
	}

	public List<Organiza> getOrganizaLists() {
		return organizaLists;
	}

	public void setOrganizaLists(List<Organiza> organizaLists) {
		this.organizaLists = organizaLists;
	}

	public OptLogService getOptLogService() {
		return optLogService;
	}

	public void setOptLogService(OptLogService optLogService) {
		this.optLogService = optLogService;
	}

	public List<Log> getLogList() {
		return logList;
	}

	public void setLogList(List<Log> logList) {
		this.logList = logList;
	}

	public String getTypes() {
		return types;
	}

	public void setTypes(String types) {
		this.types = types;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public List<Dictionary> getDataListWLJB() {
		return dataListWLJB;
	}

	public void setDataListWLJB(List<Dictionary> dataListWLJB) {
		this.dataListWLJB = dataListWLJB;
	}

}
